function calculate_Intersection_ahead() {
    // 获取输入的数据
    var A_X = parseFloat(document.getElementById("Intersection_ahead_input_A_X").value);
    var A_Y = parseFloat(document.getElementById("Intersection_ahead_input_A_Y").value);
    var A_angle = parseFloat(document.getElementById("Intersection_ahead_input_A_angle").value);
    var B_X = parseFloat(document.getElementById("Intersection_ahead_input_B_X").value);
    var B_Y = parseFloat(document.getElementById("Intersection_ahead_input_B_Y").value);
    var B_angle = parseFloat(document.getElementById("Intersection_ahead_input_B_angle").value);

    // 计算交点坐标
    var intersection_X = (A_X + Math.tan((90 - A_angle) * Math.PI / 180) * B_X - Math.tan((90 - A_angle) * Math.PI / 180) * A_X - B_Y + A_Y) / (Math.tan((90 - A_angle) * Math.PI / 180) - Math.tan((90 - B_angle) * Math.PI / 180));
    var intersection_Y = Math.tan((90 - B_angle) * Math.PI / 180) * (intersection_X - B_X) + B_Y;

    // 显示交点坐标
    document.getElementById("Intersection_ahead_out_X").value = intersection_X.toFixed(2);
    document.getElementById("Intersection_ahead_out_Y").value = intersection_Y.toFixed(2);

    // 获取输入框中的点坐标
    var A_X = parseInt(document.getElementById("Intersection_ahead_input_A_X").value);
    var A_Y = parseInt(document.getElementById("Intersection_ahead_input_A_Y").value);
    var B_X = parseInt(document.getElementById("Intersection_ahead_input_B_X").value);
    var B_Y = parseInt(document.getElementById("Intersection_ahead_input_B_Y").value);
    var C_X = parseInt(document.getElementById("Intersection_ahead_out_X").value);
    var C_Y = parseInt(document.getElementById("Intersection_ahead_out_Y").value);
    var canvas = document.getElementById("Intersection_ahead_Canvas");
    // 生成示意图
    draw(A_X, A_Y, B_X, B_Y, C_X, C_Y, canvas);
}

function calculate_Intersection_distance() {
    // 获取输入框中的值
    var A_X = parseFloat(document.getElementById("Intersection_distance_input_A_X").value);
    var A_Y = parseFloat(document.getElementById("Intersection_distance_input_A_Y").value);
    var A_distance = parseFloat(document.getElementById("Intersection_distance_input_A_distance").value);
    var B_X = parseFloat(document.getElementById("Intersection_distance_input_B_X").value);
    var B_Y = parseFloat(document.getElementById("Intersection_distance_input_B_Y").value);
    var B_distance = parseFloat(document.getElementById("Intersection_distance_input_B_distance").value);

    // 进行距离交会计算
    var total_distance = A_distance + B_distance;
    var ratio_A = A_distance / total_distance;
    var ratio_B = B_distance / total_distance;
    var intersection_X = A_X * ratio_A + B_X * ratio_B;
    var intersection_Y = A_Y * ratio_A + B_Y * ratio_B;

    // 将结果显示在输出框中
    document.getElementById("Intersection_distance_out_X").value = intersection_X.toFixed(2);
    document.getElementById("Intersection_distance_out_Y").value = intersection_Y.toFixed(2);


    // 获取输入框中的点坐标
    var A_X = parseInt(document.getElementById("Intersection_distance_input_A_X").value);
    var A_Y = parseInt(document.getElementById("Intersection_distance_input_A_Y").value);
    var B_X = parseInt(document.getElementById("Intersection_distance_input_B_X").value);
    var B_Y = parseInt(document.getElementById("Intersection_distance_input_B_Y").value);
    var C_X = parseInt(document.getElementById("Intersection_distance_out_X").value);
    var C_Y = parseInt(document.getElementById("Intersection_distance_out_Y").value);
    var canvas = document.getElementById("Intersection_distance_Canvas");
    // 生成示意图
    draw(A_X, A_Y, B_X, B_Y, C_X, C_Y, canvas);
}

function calculateDistanceAndAngle() {
    // 获取输入框中的值
    var A_X = parseFloat(document.getElementById("distance_and_Angle_input_A_X").value);
    var A_Y = parseFloat(document.getElementById("distance_and_Angle_input_A_Y").value);
    var B_X = parseFloat(document.getElementById("distance_and_Angle_input_B_X").value);
    var B_Y = parseFloat(document.getElementById("distance_and_Angle_input_B_Y").value);

    // 计算距离
    var distance = Math.sqrt(Math.pow(B_X - A_X, 2) + Math.pow(B_Y - A_Y, 2));

    // 计算方位角
    var angle = Math.atan2(B_Y - A_Y, B_X - A_X);
    angle = angle * (180 / Math.PI); // 转换为角度
    if (angle < 0) {
        angle += 360; // 确保角度在0到360度之间
    }

    // 将结果显示在输出框中
    document.getElementById("distance_and_Angle_out_distance").value = distance.toFixed(2);
    document.getElementById("distance_and_Angle_out_angle").value = angle.toFixed(2);

    // 获取输入框中的点坐标
    var A_X = parseInt(document.getElementById("distance_and_Angle_input_A_X").value);
    var A_Y = parseInt(document.getElementById("distance_and_Angle_input_A_Y").value);
    var B_X = parseInt(document.getElementById("distance_and_Angle_input_B_X").value);
    var B_Y = parseInt(document.getElementById("distance_and_Angle_input_B_Y").value);
    var canvas = document.getElementById("distance_and_Angle_Canvas");
    var ctx = canvas.getContext("2d");
    // 生成示意图
    // 绘制点 A
    ctx.beginPath();
    ctx.arc(A_X, A_Y, 5, 0, 2 * Math.PI);
    ctx.fillStyle = "red";
    ctx.fill();
    ctx.font = "12px Arial";
    ctx.fillText("A (" + A_X + ", " + A_Y + ")", A_X + 5, A_Y - 5);

    // 绘制点 B
    ctx.beginPath();
    ctx.arc(B_X, B_Y, 5, 0, 2 * Math.PI);
    ctx.fillStyle = "blue";
    ctx.fill();
    ctx.fillText("B (" + B_X + ", " + B_Y + ")", B_X + 5, B_Y - 5);

    // 连接点 A、B、C 形成三角形
    ctx.beginPath();
    ctx.moveTo(A_X, A_Y);
    ctx.lineTo(B_X, B_Y);
    ctx.closePath();
    ctx.strokeStyle = "black";
    ctx.stroke();
}

function draw(A_X, A_Y, B_X, B_Y, C_X, C_Y, canvas) {
    // var canvas = document.getElementById("triangleCanvas");
    var ctx = canvas.getContext("2d");

    // // 获取输入框中的点坐标
    // var A_X = parseInt(document.getElementById("Intersection_ahead_input_A_X").value);
    // var A_Y = parseInt(document.getElementById("Intersection_ahead_input_A_Y").value);
    // var B_X = parseInt(document.getElementById("Intersection_ahead_input_B_X").value);
    // var B_Y = parseInt(document.getElementById("Intersection_ahead_input_B_Y").value);
    // var C_X = parseInt(document.getElementById("Intersection_ahead_out_X").value);
    // var C_Y = parseInt(document.getElementById("Intersection_ahead_out_Y").value);

    // 绘制点 A
    ctx.beginPath();
    ctx.arc(A_X, A_Y, 5, 0, 2 * Math.PI);
    ctx.fillStyle = "red";
    ctx.fill();
    ctx.font = "12px Arial";
    ctx.fillText("A (" + A_X + ", " + A_Y + ")", A_X + 5, A_Y - 5);

    // 绘制点 B
    ctx.beginPath();
    ctx.arc(B_X, B_Y, 5, 0, 2 * Math.PI);
    ctx.fillStyle = "blue";
    ctx.fill();
    ctx.fillText("B (" + B_X + ", " + B_Y + ")", B_X + 5, B_Y - 5);

    // 绘制点 C
    ctx.beginPath();
    ctx.arc(C_X, C_Y, 5, 0, 2 * Math.PI);
    ctx.fillStyle = "green";
    ctx.fill();
    ctx.fillText("P (" + C_X + ", " + C_Y + ")", C_X + 5, C_Y - 5);

    // 连接点 A、B、C 形成三角形
    ctx.beginPath();
    ctx.moveTo(A_X, A_Y);
    ctx.lineTo(B_X, B_Y);
    ctx.lineTo(C_X, C_Y);
    ctx.closePath();
    ctx.strokeStyle = "black";
    ctx.stroke();
}